﻿using Microsoft.Extensions.Caching.Memory;

namespace AuthenticationDemo.Common
{
    public static class App
    {
        public static IConfiguration Configuration { get; set; }

        public static IServiceProvider ServiceProvider { get; set; }

        public static IHostEnvironment Environment => ServiceProvider.GetRequiredService<IHostEnvironment>();

        public static HttpContext? httpContext => ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
        public static IMemoryCache memoryCache => ServiceProvider.GetRequiredService<IMemoryCache>();
        /// <summary>
        /// 获取服务
        /// 最好只获取单例注入的服务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T? GetService<T>()
        {
            return ServiceProvider.GetService<T>();
        }

    }
}
